package com.ajie.bluetoothcard.adapter;

import java.util.ArrayList;

import com.ajie.bluetoothcard.domain.CardType;
import com.ajie.bluetoothcard.ui.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * 名片分类
 * @author Jack
 *
 */
public class CardTypeAdapter extends BaseAdapter{
	private LayoutInflater mInflater;
	private ArrayList<CardType> mData = new ArrayList<CardType>();
	private Context context;
	public CardTypeAdapter(Context context){
		this.context = context;
		mInflater = LayoutInflater.from(context);
	}
	
	public CardTypeAdapter(Context context, ArrayList<CardType> data){
		this.context = context;
		mInflater = LayoutInflater.from(context);
		mData = data;
	}

	public void setData(ArrayList<CardType> data){
		mData = data;
		this.notifyDataSetChanged();
	}
	
	@Override
	public int getCount() {
		return mData.size();
	}

	@Override
	public Object getItem(int id) {
		return mData.get(id);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if(convertView == null){
			holder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.card_type_item, null);
			holder.card_type_name = (TextView)convertView.findViewById(R.id.card_type_name);
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder)convertView.getTag();
		}
		CardType cardType = (CardType)getItem(position);
		holder.card_type_name.setText(cardType.getName());
		return convertView;
	}
	
	public class ViewHolder {
		TextView card_type_name;
	}
	
}
